from .girl import Girl
from .trait import Trait
from .stat import Stat
from .girl_names import rand_name

#
# this is what happens to rgirlsx records
#
# this should be all the info needed to create a new random girl
#
class GirlTemplate(object):
	def __init__(self, *args, **kw):
		object.__init__(self)
		self.name = ""
		self.desc = ""
		self.human = True
		self.catacomb = False
	def add_stat(self, name, lo, hi):
		#print "Debug: adding {}: {}-{}".format( name, lo, hi)
		st = Stat(name = name)
		st.random = True
		st.lo_val = lo
		st.hi_val = hi
		self.__dict__[name] = st
		self.traits = []
	def add_trait(self, name, pc):
		t = Trait( name = name, percent = pc, random = True)
		print "trait {} - percent = {}".format(
			t.name, t.percent
		)
		self.traits.append(t)
	def print_(self):
		for k in self.__dict__.keys():
			v = self.__dict__[k]
			if k in [ "name", "desc", "human", "catacomb" ]:
				print "{} : {}".format(k, v)
				continue
			print "{} : {}-{}".format(
				k ,v.lo_val, v.hi_val
			)
	def make(self):
#
#		start with a girl
#
		girl = Girl()
#
#		__dict__ has all the object attributes
#		we're going to iterate over the keys of that dict
#
#		and the keys should be the girl stat names
#
		#print "Debug: making ", self.name
		girl.status = "Slave"
		for stat_name in self.__dict__.keys():
			#print "Debug: key = ", stat_name
			stat_obj = self.__dict__[stat_name]
#
#			name and description we don't need
#
			if stat_name == "name":
				girl.arch_name = self.name
				girl.name = rand_name()
				continue
			if stat_name == "desc":
				girl.__dict__[stat_name] = stat_obj
				continue
			if stat_name == "human":
				#print "Debug: Human = '{}'".format(stat_obj)
				if stat_obj == False:
					#print "Debug: adding 'Not Human' trait"
					girl.add_trait("Not Human")
				continue
			if stat_name == "catacomb":
				if stat_obj == True:
					girl.status = "Catacombs"
				continue
			if stat_name == "traits":
				continue
			try:
				stat_obj.randomise()
			except:
				s = "exception randomising ", stat_name
				print s
				raise
			girl.__dict__[stat_name] = stat_obj.value
		#print "Debug: End of key loop"

		for trait in self.traits:			
			if trait.test():
				girl.add_trait(trait.name)
		girl.pics.scan(girl)
		return girl

